#ifndef CONTEXTFREEGRAMMAR_H
#define CONTEXTFREEGRAMMAR_H

#include <iostream>

#include "defs.h"

class FirstFollowGenerator;

class ContextFreeGrammar
{
    friend FirstFollowGenerator;
public:

    ContextFreeGrammar(std::istream & in);
    virtual ~ContextFreeGrammar();

    void PrintNonterminal(std::ostream & out = std::cout);
    void PrintTerminal(std::ostream & out = std::cout);
    void PrintProduction(std::ostream & out = std::cout);
    //

protected:

    StringSet::const_iterator GetEpsilon() const;
    StringSet::const_iterator GetEndOfFile() const;
    void PrintProductionRight(const ProductionList & pl, std::ostream & out = std::cerr) const;

    std::string GenerateUniqueName(const std::string & prefix);

    bool isNonterminal(const std::string & str) const;

    std::string SafePrint(StringSet::const_iterator itr) const;

    StringSet::iterator startSymbol;

    StringSet nonterminal, terminal;
    ProductionMap production;

private:

};

#endif // CONTEXTFREEGRAMMAR_H
